//监听鼠标在speed容器上的移动
//获取鼠标在y轴上的移动距离

var speed = document.querySelector('.speed')
var bar = document.querySelector('.speed-bar')
var video = document.querySelector('.flex')

//addEventListener:监听函数
speed.addEventListener('mousemove',function(e)
{
    //console.log(speed.offsetTOP);//offsetTop为获取某dom结构到浏览器头部距离
    //console.log(e.pageY);
    var y = e.pageY - speed.offsetTop
    var percent = y / speed.offsetHeight//offsetHeight为获取某dom结构自身高度
    var height = Math.round(percent*100) + '%'//4舍5入
    var min = 0.4
    var max = 4
    var playbackRate = percent * (max - min) + min
    //设置speed-bar的高度
    bar.style.height = height
    bar.textContent = playbackRate.toFixed(2) + 'x'//.toFixed(X)保留x位小数

    //控制视频播放速度
    video.playbackRate = playbackRate
})
